/**
* All Rights Reserved , Copyright (C) 2022 , 青岛鼎信通讯股份有限公司
*
* MpmProjectUnBidScoreService
* 评标细则不创建申请表
*
* 修改纪录
* 2022-05-24 版本：1.0 hudeyong 创建。
* @version 版本：1.0
* @author 作者：hudeyong
* 创建日期：2022-05-24
*/
package com.topscomm.mpm.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.topscomm.mpm.service.IMpmProjectUnBidScoreService;
import com.topscomm.mpm.service.impl.auto.MpmProjectUnBidScoreServiceAuto;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.tap.TapEntity;
import com.topscomm.tap.common.SessionUserBean;


import com.topscomm.basic.BasicEntity;
import com.topscomm.basic.util.PrimaryKeyUtil;
import com.topscomm.cbo.pojo.CboApprovalFlowInsEntity;
import com.topscomm.cbo.pojo.CboApprovalNodeEntity;
import com.topscomm.cbo.pojo.CboApprovalNodeInsEntity;
import com.topscomm.cbo.service.ICboApprovalFlowInsService;
import com.topscomm.mpm.pojo.MpmProjectBidScoreEntity;
import com.topscomm.mpm.pojo.MpmProjectBidScoreHisEntity;
import com.topscomm.mpm.pojo.MpmProjectEntity;
import com.topscomm.mpm.pojo.MpmProjectUnBidScoreEntity;

@Service(value = "mpmProjectUnBidScoreService")
@Scope(value = "singleton")
public class MpmProjectUnBidScoreService extends MpmProjectUnBidScoreServiceAuto implements IMpmProjectUnBidScoreService {
	@Autowired
	MpmProjectService mpmProjectService;
	/**
	 * @author: hudeyong
	 * @date: 2022-05-24
	 * @param entity
	 * @throws ServiceException
	 * @description:单号生成
	 * @modify:
	 */
	@Override
	protected void beforeInsert(BasicEntity entity){
		super.beforeInsert(entity);
		if (entity.getId() <= 0) {// 赋值Id和单号
			long[] arrayId = PrimaryKeyUtil.GeneIDs(entity.getTableName(), 1);
			entity.setId(arrayId[0]);
			String docNo = String.valueOf(arrayId[0]);
			docNo = docNo.substring(0, 6) + docNo.substring(9);
			entity.setValue(MpmProjectUnBidScoreEntity.FieldDocno, docNo);
		}
	}


	/**
	 *
	 * @description: 审批通过后的处理
	 * @param billEntity
	 * @param nodeIns
	 * @param node
	 * @param sessionUserBean
	 * @author: hdy
	 * @date: 2022年4月26日
	 * @modify:
	 */
	@Override
	protected void afterApprove(TapEntity billEntity, CboApprovalNodeInsEntity nodeIns, CboApprovalNodeEntity node,
			SessionUserBean sessionUserBean) {
		String soucreid = ConvertUtil.convertToString(nodeIns.getSourceid());
		MpmProjectUnBidScoreEntity unBidScoreEntity = this.queryById(soucreid);
		if(unBidScoreEntity == null) {
			return;
		}
		String projectcode = unBidScoreEntity.getProjectcode();
		String state = ConvertUtil.convertToString(unBidScoreEntity.getState());
		StringBufferProxy sql = new StringBufferProxy();
		// 审批通过或退回
		// 修改主表无评分细则审批状态
		if("9".equals(state) || "2".equals(state)) {
			sql.clear();
			sql.appendSingle("UPDATE MPMPROJECT SET EXISTBIDSCORESTATE = '{0}' WHERE PROJECTCODE = '{1}'",state, projectcode);
			this.updateExecute(sql.toString());
		}
		super.afterApprove(billEntity, nodeIns, node, sessionUserBean);
	}

}
